<template>
	<view class="home">
		<view class="search-holder">
			<view class="search-btn">
				<image src="/static/icons/search.png" mode=""></image>
			</view>
			<view class="cart-btn" @tap="toCart">
				<image src="/static/icons/cart.png" mode=""></image>
			</view>
		</view>

		<home-banner :dataList="bannerList"></home-banner>
		<home-categorys :dataList="categoryList"></home-categorys>
		<home-recommend :dataList="recommendList"></home-recommend>
		<home-hot-list :dataList="hotList"></home-hot-list>
		<home-new-list :dataList="newList"></home-new-list>
		<home-like :dataList="likeList"></home-like>
	</view>
</template>

<script>
	import {
		requestBannerAds,
		requestCategorys,
		requestRecommendList,
		requestHotList,
		requestNewList,
		requestLikeList
	} from 'api/home/home.js'
	import HomeBanner from 'pages/home/home-banner'
	import HomeCategory from 'pages/home/home-categorys'
	import HomeRecammend from 'pages/home/home-recommend'
	import HomeHotList from 'pages/home/home-hot-list'
	import HomeNewList from 'pages/home/home-new-list'
	import HomeLike from 'pages/home/home-like'
	export default {
		data() {
			return {
				bannerList: [],
				categoryList: [],
				recommendList: [],
				hotList: [],
				likeList: [],
				newList: [],
				code: '1308336521604599809',
			};
		},
		methods: {
			toCart() {
				uni.navigateTo({
					url: '/pages/user/cart/cart'
				})
			},
			async getBannerAds() {
				await requestBannerAds().then(res => {
					this.bannerList = res.data.items;
					// console.log(res)
				});
			},
			async getCategorys() {
				await requestCategorys(this.code).then(res => {
					// console.log(res);
					this.categoryList = res.data.category.children;
				})
			},
			async getRecommendList() {
				await requestRecommendList().then(res => {
					// console.log(res);
					this.recommendList = res.data.items;
				})
			},
			async getHotList() {
				await requestHotList().then(res => {
					// console.log(res);
					this.hotList = res.data.items;
				})
			},
			async getLikeList() {
				await requestLikeList().then(res => {
					// console.log(res.data.items);
					this.likeList = res.data.items;
				})
			},
			async getNewList() {
				await requestNewList().then(res => {
					// console.log(res);
					this.newList = res.data.productList;
				})
			},
			async init() {
				await this.getBannerAds();
				await this.getCategorys();
				await this.getRecommendList();
				await this.getHotList();
				await this.getLikeList();
				await this.getNewList();
				uni.stopPullDownRefresh();
			}
		},
		onPullDownRefresh(){
			this.init();
		},
		onLoad() {
			this.init();
		},
		components: {
			'home-banner': HomeBanner,
			'home-categorys': HomeCategory,
			'home-recommend': HomeRecammend,
			'home-hot-list': HomeHotList,
			'home-new-list': HomeNewList,
			'home-like': HomeLike,
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		width: 100%;
		min-height: 100vh;

		.search-holder {
			display: flex;
			position: absolute;
			top: 0;
			right: 0;
			z-index: 99;
			box-sizing: border-box;
			padding: 30rpx;
			height: 42rpx;

			image {
				margin-left: 45rpx;
				width: 42rpx;
				height: 42rpx;
			}
		}
	}
</style>
